package com.czxy.service;

import com.czxy.dao.ProductMapper;
import com.czxy.domain.Product;
import com.czxy.utils.MyBatisUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class ProductService {





         public List<Product> findAll(){

             ProductMapper mapper = MyBatisUtils.getMapper(ProductMapper.class);

             List<Product> list = mapper.selectAll();

             MyBatisUtils.close();


             return list;

         }


         public  Product findByPk(Product product){

             ProductMapper mapper = MyBatisUtils.getMapper(ProductMapper.class);
             Product p = mapper.selectByPrimaryKey(product);

             MyBatisUtils.close();

             return p;

         }




         public PageInfo findByPg(int pageNum, int pageSize){

             ProductMapper mapper = MyBatisUtils.getMapper(ProductMapper.class);


             PageHelper.startPage(pageNum,pageSize);

             List<Product> products = mapper.selectAll();


             PageInfo<Product> pageInfo = new PageInfo<>(products);


             MyBatisUtils.close();


             return pageInfo;
         }


         public  void  del (String pid){

             ProductMapper mapper = MyBatisUtils.getMapper(ProductMapper.class);

             int i = mapper.deleteByPrimaryKey(pid);

             MyBatisUtils.commitAndClose();


             System.out.println("影响了" + i);


         }



















    }













